package com.wwy.user.service.impl;

import com.wwy.user.converter.UserConverter;
import com.wwy.user.mapper.UserMapper;
import com.wwy.user.module.entity.User;
import com.wwy.user.module.vo.user.UserSaveVo;
import com.wwy.user.module.vo.user.UserUpdateVo;
import com.wwy.user.module.vo.user.UserVo;
import com.wwy.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Transactional(rollbackFor = Exception.class)
public class UserUserImpl implements UserService {

//	@Resource
//	private UserConverter userConverter;

	@Resource
	private UserMapper userMapper;

	@Override
	public void save(UserSaveVo saveVo) {
		User user = UserConverter.INSTANCE.toUser(saveVo);
        userMapper.insert(user);
	}

	@Override
	public void deleteById(String id) {
		userMapper.deleteById(id);
	}

	@Override
	public void updateById(UserUpdateVo updateVo) {
		User user = UserConverter.INSTANCE.toUser(updateVo);
		userMapper.updateById(user);
	}

	@Override
	public UserVo getById(String id) {
		User user = userMapper.selectById(id);
		return UserConverter.INSTANCE.toUserVo(user);
	}

}
